package com.controller.student;

import com.dto.excution.ListExcution;
import com.entity.StudentInfo;
import com.enums.ListEnum;
import com.service.StudentService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("student")
public class StudentController {

    @Autowired
    private StudentService service;


    @ApiOperation(value = "学生发布")
    @PostMapping(value = "publish")
    @ResponseBody
    public ListExcution<Void> publish(Integer userId,String studentName, String studentSex, String teachStage, String counselingMethod, Integer cityId, Integer locationId, String adress, String classTime, String subjects, String teacherSex, String salary, String overview) {
        int Publish = service.publish(userId,studentName, studentSex, teachStage, counselingMethod, cityId, locationId, adress, classTime, subjects, teacherSex, salary, overview);
        if (Publish > 0) {
            return new ListExcution<Void>(null, ListEnum.ADDSUCCESS);
        } else {
            return new ListExcution<Void>(null, ListEnum.ADDFAIL);
        }
    }

    @ApiOperation(value = "查询发布条数")
    @PostMapping(value = "findPublishCount")
    @ResponseBody
    public ListExcution<Integer> findPublishCount(Integer userId){
        int publishCount=service.findPublishCount(userId);
        return new ListExcution<Integer>(publishCount,ListEnum.SUCCESS);
    }

    //userid 查询 stu表user表
    @ApiOperation(value = "我的发布")
    @PostMapping(value = "findPublish")
    @ResponseBody
    public ListExcution<StudentInfo> findPublish(Integer userId){
        StudentInfo stu=service.findPublish(userId);
        return new ListExcution<StudentInfo>(stu,ListEnum.SUCCESS);
    }

    @ApiOperation(value = "删除我的发布")
    @PostMapping(value = "deletePublish")
    @ResponseBody
    public ListExcution<Void> deletePublish(Integer id,Integer userId,Integer count){
        int pul= service.deletePublish(id,userId,count);
        if(pul>0){
            return new ListExcution<Void>(null,ListEnum.SUCCESS);
        }else {
            return new ListExcution<Void>(null,ListEnum.FAIL);
        }
    }

    @ApiOperation(value = "查询(筛选)学生")
    @PostMapping(value = "seekStudent")
    @ResponseBody
    public ListExcution<List<StudentInfo>> seekStudent(String cityName,Integer locationId,Integer subjectId,String teachStage,Integer limit){
        List<StudentInfo> list=service.seekStudent(cityName,locationId,subjectId,teachStage,limit);
        return new ListExcution<List<StudentInfo>>(list, ListEnum.SUCCESS);
    }

    @ApiOperation(value = "查询学生详情")
    @PostMapping(value = "findStudentDetail")
    @ResponseBody
    public ListExcution<StudentInfo> findStudentDetail(Integer userId){
        StudentInfo info = service.findStudentDetail(userId);
        return new ListExcution<StudentInfo>(info, ListEnum.SUCCESS);
    }

    /**
     *
     * @param studentName 学员姓名
     * @param studentSex 学员性别
     * @param teachStage 教育阶段
     * @param counselingMethod 辅导方式
     * @param cityId 城市内码
     * @param locationId 区域内码
     * @param adress 具体地址
     * @param classTime 授课时间
     * @param subjectId 科目ID
     * @param teacherSex 老师性别
     * @param salary 期望薪资
     * @param overview 需求概况
     * @return
     */
    @ApiOperation(value = "发布更改")
    @PostMapping(value = "updatePublish")
    @ResponseBody
    public ListExcution<Void>updatePublish(Integer userId,String studentName,String studentSex,String teachStage,String counselingMethod,Integer cityId,Integer locationId,String adress,String classTime,String subjectId,String teacherSex,String salary,String overview){
           int publish=service.updatePublish(userId,studentName,studentSex,teachStage,counselingMethod,cityId,locationId,adress,classTime,subjectId,teacherSex,salary,overview);
           if(publish>0){
               return  new ListExcution<Void>(null, ListEnum.SUCCESS);
           }else {
               return  new ListExcution<Void>(null, ListEnum.FAIL);
           }

    }
    @ApiOperation(value = "查看是否发布")
    @PostMapping(value = "findPublishState")
    @ResponseBody
    public ListExcution<Void> findPublishState(Integer userId){
        int  count = service.findPublishState(userId);
        if(count>0){
            return  new ListExcution<Void>(null, ListEnum.SUCCESS);
        }else {
            return  new ListExcution<Void>(null, ListEnum.FAIL);
        }
    }
}